package api

import (
	"api-gateway/basic/config"
	__ "api-gateway/basic/proto"
	"api-gateway/handler/request"
	"github.com/gin-gonic/gin"
	"net/http"
)

func AddReservation(c *gin.Context) {
	var req request.AddReservation
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code":    400,
			"message": "验证失败",
			"data":    err.Error(),
		})
		return
	}
	serv, err := config.UserClient.AddReservation(c, &__.AddReservationReq{
		UserId:      int64(req.UserId),
		ServiceType: req.SerViceType,
		JobTime:     req.JobTime,
		CleanerId:   int64(req.CleanerId),
		Address:     req.Address,
	})
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code":    400,
			"message": "添加预约失败",
			"data":    err.Error(),
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code":    200,
		"message": "添加预约成功",
		"data":    serv,
	})
}

func ReservationList(c *gin.Context) {
	var req request.ReservationList
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code":    400,
			"message": "验证失败",
			"data":    err.Error(),
		})
		return
	}
	list, err := config.UserClient.ReservationList(c, &__.ReservationListReq{})
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code":    400,
			"message": "服务列表展示失败",
			"data":    err.Error(),
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code":    200,
		"message": "服务列表展示成功",
		"data":    list,
	})
}
